#!/usr/bin/env python	 
#	 
import os	 
import sys	
import datetime
	
# Hardwire in appengine modules to PYTHONPATH	 
# or use wrapper to do it more elegantly	
appengine_dirs = ['/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/','/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/yaml/lib','/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webob/','/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/django/',os.path.dirname(__file__)+'/../']	
sys.path.extend(appengine_dirs)	 
# Add your models to path	 
my_root_dir = os.path.abspath(os.path.dirname(__file__))	
sys.path.insert(0, my_root_dir)	 
	
from google.appengine.ext import db	 
from google.appengine.ext.remote_api import remote_api_stub	 
import getpass	
	
import uzdb

APP_NAME = 'urlzen'	 
os.environ['AUTH_DOMAIN'] = 'gmail.com'	 
os.environ['USER_EMAIL'] = 'jackson.h.miller@gmail.com'	 

	
def auth_func():	
	return (raw_input('Username:'), getpass.getpass('Password:'))	 
	
# Use local dev server by passing in as parameter:	
# servername='localhost:8080'	 
# Otherwise, remote_api assumes you are targeting APP_NAME.appspot.com	
remote_api_stub.ConfigureRemoteDatastore(APP_NAME,	
 '/remote_api', auth_func,servername='2.latest.urlzen.appspot.com')	

user = 'jackson.h.miller@gmail.com'
# update all models for jaxn
#urls = uzdb.Url.all().filter('twitter_users =','jaxn').fetch(1000)
urls = db.GqlQuery("SELECT * FROM Url WHERE twitter_users='jaxn'").fetch(1000)
for url in urls:
	if not url.users:
		url.users = []
	if not user in url.users:
		url.users.append(user)
		url.put()
